-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Proper pep695 generic function docstrings #5743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Proper pep695 generic function docstrings #5743
Conversation
Signed-off-by: Michael Carlstrom <[email protected]>
|
@timohl if you have any comments/suggestions please let me know. |
|
I should find time to review the code in more detail during the weekend, but I already skimmed through the tests and the new syntax looks nice. :) One thing that came to my mind though is backwards compatibility. Also, what is the impact of the check for |
From what I can tell mypy's stubgen or pybind11-stubgen currently ignore the inside of pep695. Mypy has a todo. Mypy will fail if running in version less than 3.12 def foo[T](a: T) -> T: ... # invalid syntaxHowever, mypy could when implementing support generate pre-pep695 syntax in stubs when ran on older python versions. import typing
T = typing.TypeVar("T")
def foo(a: T) -> T: ... # valid |
|
I don't know how much this would get used but it would be a nice addition to pybind11. I added very basic support for this syntax to my fork of pybind11-stubgen. It only supports the un-type-hinted variant. Looks like the tests are failing due to our changes to type hints. |
Description
Add
typevar_recordto hold information about function type variables. Use these type variables to update the generated docstrings as according to pep695.To be used in conjuction with the typevar types introduced in #5167.
Suggested changelog entry:
typevar_recordto add pep695 generics to function docstrings.